# -*- coding: utf-8 -*-

from multiprocessing import Process
from threading import Thread
import time
def work1():    # 计算密集型任务
    res = 0
    for i in range(10000000):
        res += i
def work2():    # IO密集型任务
    time.sleep(2)
if __name__ == '__main__':
    l = []
    start = time.time()
    for i in range(8):
        # 进程之间切换效率低
        # p = Process(target=work1)   # 主1.3895211219787598
        # p = Process(target=work2)   # 主2.202115774154663
        # 毕竟计算效率低，但是切换效率高
        # p = Thread(target=work1)    # 主5.590560674667358
        p = Thread(target=work2)    # 主2.0132291316986084
        l.append(p)
        p.start()
    for p in l:
        p.join()
    print('主%s' % (time.time() - start))
